{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 13.2 \u7ec8\u6b62\u7a0b\u5e8f\u5e76\u7ed9\u51fa\u9519\u8bef\u4fe1\u606f\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u95ee\u9898\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u60f3\u5411\u6807\u51c6\u9519\u8bef\u6253\u5370\u4e00\u6761\u6d88\u606f\u5e76\u8fd4\u56de\u67d0\u4e2a\u975e\u96f6\u72b6\u6001\u7801\u6765\u7ec8\u6b62\u7a0b\u5e8f\u8fd0\u884c"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u89e3\u51b3\u65b9\u6848\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u6709\u4e00\u4e2a\u7a0b\u5e8f\u50cf\u4e0b\u9762\u8fd9\u6837\u7ec8\u6b62\uff0c\u629b\u51fa\u4e00\u4e2a SystemExit \u5f02\u5e38\uff0c\u4f7f\u7528\u9519\u8bef\u6d88\u606f\u4f5c\u4e3a\u53c2\u6570\u3002\u4f8b\u5982\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "raise SystemExit('It failed!')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5b83\u4f1a\u5c06\u6d88\u606f\u5728 sys.stderr \u4e2d\u6253\u5370\uff0c\u7136\u540e\u7a0b\u5e8f\u4ee5\u72b6\u6001\u78011\u9000\u51fa\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u8ba8\u8bba\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u672c\u8282\u867d\u7136\u5f88\u77ed\u5c0f\uff0c\u4f46\u662f\u5b83\u80fd\u89e3\u51b3\u5728\u5199\u811a\u672c\u65f6\u7684\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u3002\n\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u4f60\u60f3\u8981\u7ec8\u6b62\u67d0\u4e2a\u7a0b\u5e8f\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u50cf\u4e0b\u9762\u8fd9\u6837\u5199\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import sys\nsys.stderr.write('It failed!\\n')\nraise SystemExit(1)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5982\u679c\u4f60\u76f4\u63a5\u5c06\u6d88\u606f\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9 SystemExit() \uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u7701\u7565\u5176\u4ed6\u6b65\u9aa4\uff0c\n\u6bd4\u5982import\u8bed\u53e5\u6216\u5c06\u9519\u8bef\u6d88\u606f\u5199\u5165 sys.stderr"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.1"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": true,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}